home *** CD-ROM | disk | FTP | other *** search
- #! /bin/sh
- # This is a shell archive, meaning:
- # 1. Remove everything above the #! /bin/sh line.
- # 2. Save the resulting text in a file.
- # 3. Execute the file with /bin/sh (not csh) to create:
- # Makefile
- # README
- # go2latex.y
- # go2ps.y
- # gopro.ps
- # input.l
- # main.c
- # printps
- # sample.input
- # This archive created: Sat Jan 12 22:40:12 1991
- export PATH; PATH=/bin:/usr/bin:$PATH
- if test -f 'Makefile'
- then
- echo shar: "will not over-write existing file 'Makefile'"
- else
- cat << \SHAR_EOF > 'Makefile'
- SHELL=/bin/sh
- BIN= /usr/esh/bin
- CFLAGS= -DLEXDEBUG -DYYDEBUG
- OFILES= lex.yy.o y.tab.o main.o
-
- go2latex: $(OFILES)
- cc $(OFILES) -o go2latex -ll
-
- y.tab.h y.tab.c: go2latex.y
- yacc -d go2latex.y
-
- $(OFILES): y.tab.h yy.lex.c Makefile
-
- yy.lex.c: input.l
- lex input.l
- SHAR_EOF
- fi
- if test -f 'README'
- then
- echo shar: "will not over-write existing file 'README'"
- else
- cat << \SHAR_EOF > 'README'
- >From: Sean Hayes <esh@hplb.hpl.hp.com>
-
- Please find enclosed some stuff for generating latex documents
- from Greg Hale's board postings. (NB this uses the ascii part and not the
- Smart Go stuff, which has to be removed). I was hoping to be able to
- spend more effort on making this a little slicker, but I haven't had time.
- This is offered totally free, no acknowledments required, but
- I would like to hear if anybody improves on it.
-
- ---
- Later:
-
- I still think the best approach is to make these text boards one
- of the input formats for convert. But in any case, what I have done
- is to used Jan van der Steen's postscript code as the setup file.
- This allows (at least) two types of stone printing:
-
- (n) x y wst % this prints a white stone labelled with n (this must
- % be an integer), offset from *the middle of the board*
- % by x and y (the lower left quadrant is +ve x +ve y)
-
- x y ws % this prints an unlabbelled white stone
- % also offset from the middle of the board
- % by x and y
-
- And there are the corresponding bst and bs functions. The code attatched
- at the bottom will generate postscript diagrams from the text parse (its
- really easy!).
- Current deficiencies,
- 1 if you put characters on the board then it generates a call
- to the non-existent label function. this should put a character
- on the board in the right place (as you often find in the books).
- 2 it assumes numbers are alternating turns, beginning with black.
- It would be better to add some key in the board to say who plays
- first. (or maybe use +n for black -n for white?)
-
- And I'm sure you can think of many more. Why don't you have a play
- with it and make any alterations you think fit. If you intend to use
- this and/or distribute it you ought to get in touch with Jan, as we
- are using code he asks to obtain written permission for.
- I am happy to keep discussing this, but I really must do some work now!
- Enjoy,
- Sean.
-
-
- Change 'go2latex' into 'go2ps' to get the postscript code.
-
-
- A sample input file is included.
-
- SHAR_EOF
- fi
- if test -f 'go2latex.y'
- then
- echo shar: "will not over-write existing file 'go2latex.y'"
- else
- cat << \SHAR_EOF > 'go2latex.y'
-
- %{
-
- /* YACC grammar for the Postings on rec.games.go by Greg Hale.
- * Sean Hayes . August 9 1983
- */
-
- #include <stdio.h>
- #define YYDEBUG 1
- extern FILE *infp, *outfp;
- extern char * yytext;
- int i, j;
- char *index_chars = "abcdefghijklmnopqrst";
-
- yyerror(s)
- char * s;
- { printf(" SYNTAX ERROR - The old yacc standard!\n %s");
- exit(-1);
- }
-
- %}
-
- %union {
- int ival;
- char sval[22];
- }
-
- %token <ival> NUMBER PLUS_DASH_PLUS
- %token <sval> MOVE CHAR
-
- /* grammar symbols */
- %token BAR DOTS DOT WHITE BLACK HANDICAP_PT
- %%
- start: moves
- {
- printf("\\end{document}\n");
- }
-
- moves: moves words
- | moves position
- | /* */ {
- printf("\\documentstyle[11pt]{report}\n");
- printf("\\begin{document}\n");
- }
- ;
-
- position: PLUS_DASH_PLUS
- { printf("\n\\begin{tabular}{r|");
- for(j = 0, i = $1 - 5; i > 0; i-=2) putc('c',stdout);
- printf("|l}\n\\ & ");
- for(i = $1 - 5; i > 0; i-=2)
- printf("%c & ", index_chars[j++]);
- printf("\\ \\\\\n\\hline",$1);
- }
- lines PLUS_DASH_PLUS
- { printf("\\hline\n\\end{tabular}\n\\\\\n\\\\\n");
- }
-
- ;
-
- lines: NUMBER { printf(" %d ", $1); } BAR points BAR NUMBER
- { printf(" & %d \\\\\n", $6); } lines
- | BAR DOTS lines
- | /* empty */
- ;
-
- points: points point
- | point
- ;
-
- point: DOT
- { printf(" & $\\cdot$"); }
- | WHITE
- { printf(" & {\\Huge $\\circ$}"); }
- | BLACK
- { printf(" & {\\Huge $\\bullet$}"); }
- | MOVE
- { printf(" & {\\small $%c$}", $1[0]); }
- | HANDICAP_PT
- { printf(" & {\\tiny $\\bullet$}"); }
- | NUMBER
- { printf(" & {\\small $%d$} ", $1); }
- ;
-
- words: words CHAR
- { printf("%c",$2[0]); }
- | /* */
- ;
-
-
- SHAR_EOF
- fi
- if test -f 'go2ps.y'
- then
- echo shar: "will not over-write existing file 'go2ps.y'"
- else
- cat << \SHAR_EOF > 'go2ps.y'
-
- %{
-
- /* YACC grammar for the Postings on rec.games.go by Greg Hale.
- * This one generates postscript.
- * Sean Hayes . August 9 1983
- */
-
- #include <stdio.h>
- #define YYDEBUG 1
- #define BoardSize 19
- #define BLACKMOVE "bst"
- #define WHITEMOVE "wst"
- extern FILE *infp, *outfp;
- extern char * yytext;
- int i, j;
- char *index_chars = "abcdefghijklmnopqrst";
-
- typedef struct posn {
- int row;
- int col;
- } Position;
-
- int currentRow = 1;
- int currentCol = 1;
- int figures = 1;
- int numWhite = 0, numBlack = 0;
- int turn = 0;
-
- yyerror(s)
- char * s;
- { printf(" SYNTAX ERROR - The old yacc standard!\n %s");
- exit(-1);
- }
-
- %}
-
- %union {
- int ival;
- char sval[22];
- }
-
- %token <ival> NUMBER PLUS_DASH_PLUS
- %token <sval> MOVE CHAR
-
- /* grammar symbols */
- %token BAR DOTS DOT WHITE BLACK HANDICAP_PT
- %%
- start: moves
- { printf("showpage\n");
- }
-
- moves: moves words
- | moves position
- | /* */ {
- }
- ;
-
- position: PLUS_DASH_PLUS {currentRow = 1; printf("\nboard\n"); }
- lines PLUS_DASH_PLUS
- { printf("(Figure %d) comment\n", figures++);
- }
- ;
-
- lines: NUMBER BAR points BAR NUMBER
- { currentCol = 1; currentRow++;
- }
- lines
- | BAR DOTS { currentCol = 1; currentRow++;
- }
- lines
- | /* empty */
- ;
-
- points: points point
- | point
- ;
-
- point: DOT
- {
- currentCol++;
- }
- | WHITE
- { printf("%d %d ws\n",currentCol - 10, currentRow - 10);
- currentCol++;
- }
- | BLACK
- { printf("%d %d bs\n",currentCol - 10, currentRow - 10);
- currentCol++;
- }
- | MOVE
- { printf(" (%c) %d %d label \n", $1[0], currentCol - 10, currentRow - 10);
- currentCol++;
- }
- | HANDICAP_PT
- {
- currentCol++;
- }
- | NUMBER
- { printf("(%d) %d %d ", $1, currentCol - 10, currentRow - 10);
- currentCol++;
- if (turn == 0){
- turn = 1;
- printf("%s\n", BLACKMOVE);
- }
- else {
- turn = 0;
- printf("%s\n", WHITEMOVE);
- }
- }
- ;
-
- words: words CHAR
- { }
- | /* */
- ;
-
-
- SHAR_EOF
- fi
- if test -f 'gopro.ps'
- then
- echo shar: "will not over-write existing file 'gopro.ps'"
- else
- cat << \SHAR_EOF > 'gopro.ps'
- %!
- % *************************************************
- % * *
- % * Jan van der Steen *
- % * jansteen@cwi.nl *
- % * Amsterdam *
- % * The Netherlands *
- % * *
- % *************************************************
- %
- /corrections [
- 0 0 0 0 0 0 0 0 0 -5
- 0 -5 -5 -5 -5 -5 -5 -5 -5 0
- 5 0 0 0 0 0 0 0 0 0
- 5 0 0 0 0 0 0 0 0 0
- 5 0 0 0 0 0 0 0 0 0
- 5 0 0 0 0 0 0 0 0 0
- 5 0 0 0 0 0 0 0 0 0
- 5 0 0 0 0 0 0 0 0 0
- 5 0 0 0 0 0 0 0 0 0
- 5 0 0 0 0 0 0 0 0 -2
- ] def
-
- /boardline .01 def
- /border .07 def
- /whiteborder .02 def
- /blackrad .48 def
- /whiterad .48 def
- /hoshirad .10 def
- /strsize .75 def
-
- /upi 72 def
- /cpi 2.54 def
- /initdone 0 def
-
- /lastdx 0 def
- /lastdy 0 def
- /row 0 def
- /col 1 def
- /ibg 4 def
- /linelength 8.3 cpi mul def
- /pagelength 12 cpi mul def
-
- /dpi {
- 72 0 matrix defaultmatrix dtransform
- /yres exch def /xres exch def
- xres dup mul yres dup mul add sqrt
- } def
- /dpu { dpi upi div } def
- /dpc { dpi mul cpi div } def
- /dpg { gridmax 2 mul diawidth exch div cvi } def
- /upg { dpg dpu div } def
-
- /boardinit {
- /realsize exch def
- /boardsize exch def
- initdone 0 eq {
- /gap
- realsize boardsize div ibg mul
- def
- /rowmax
- pagelength gap 3 mul sub
- realsize gap add div cvi
- def
- /colmax
- linelength gap 3 mul sub
- realsize gap add div cvi
- def
- rowmax 0 eq colmax 0 eq and {
- /rowmax 1 def
- /colmax 1 def
- } if
- /diawidth realsize dpc def
- /gridmax
- boardsize 1 sub 2 div
- def
- upg dup scale
- /initdone 1 def
- } if
- } def
-
- /correct {
- cvi
- dup 100 le {
- corrections exch 1 sub get
- 100 div
- }{
- pop 0
- } ifelse
- } bind def
-
- /transboard {
- lastdx neg lastdy neg translate
- row rowmax lt {
- /row row 1 add def
- } {
- col colmax lt {
- /col col 1 add def
- /row 1 def
- } {
- gsave
- showpage
- grestore
- /row 1 def
- /col 1 def
- } ifelse
- } ifelse
- /lastdx
- gridmax 2 mul 1 add ibg add col 1 sub mul
- gridmax add ibg 2 mul add
- def
- /lastdy
- gridmax 2 mul 1 add ibg add row 1 sub mul
- gridmax add ibg 2 mul add
- def
- lastdx lastdy translate
- } bind def
-
- /hoshipos {
- gridmax 9 eq {
- 6
- } {
- gridmax 6 eq {
- 3
- } {
- 2
- } ifelse
- } ifelse
- } bind def
-
- /hoshipoint {
- newpath
- hoshirad 0 360 arc
- 0 setgray
- fill
- } def
-
- /hoshi {
- 0 0 hoshipoint
- hoshipos hoshipos hoshipoint
- hoshipos hoshipos neg hoshipoint
- hoshipos neg hoshipos hoshipoint
- hoshipos neg hoshipos neg hoshipoint
- gridmax 9 eq {
- 0 hoshipos hoshipoint
- hoshipos 0 hoshipoint
- 0 hoshipos neg hoshipoint
- hoshipos neg 0 hoshipoint
- } if
- } def
-
- /board {
- transboard
- newpath
- boardline setlinewidth
- gridmax neg 1 gridmax {
- gridmax neg moveto
- 0 gridmax gridmax neg sub rlineto
- } for
- gridmax neg 1 gridmax {
- gridmax neg exch moveto
- gridmax gridmax neg sub 0 rlineto
- } for
- stroke
- newpath
- gridmax neg gridmax moveto
- 0 gridmax 2 mul neg rlineto
- gridmax 2 mul 0 rlineto
- 0 gridmax 2 mul rlineto
- closepath
- border setlinewidth
- stroke
- hoshi
- } def
-
- /ws {
- newpath
- neg whiterad 0 360 arc
- gsave
- 1 setgray
- fill
- grestore
- 0 setgray
- whiteborder setlinewidth
- stroke
- } bind def
-
- /bs {
- newpath
- neg blackrad 0 360 arc
- 0 setgray
- fill
- } bind def
-
- /whatsize {
- stringwidth
- pop
- /sw exch def
- sw strsize gt {
- % strsize sw div
- % dup scale
- strsize sw div 1 scale
- } if
- } bind def
-
- /centerstrn {
- sw 2 div neg
- strsize 2 div
- 10 100 div sub
- neg
- moveto
- dup
- correct 0 rmoveto
- show
- } bind def
-
- /wst {
- gsave
- dup 3 -1 roll
- dup 3 -1 roll
- ws
- exch
- neg
- translate
- whitefont
- dup
- whatsize
- 0 setgray
- centerstrn
- grestore
- } bind def
-
- /label {
- gsave
- %dup 3 -1 roll
- %dup 3 -1 roll
- exch
- neg
- translate
- whitefont
- dup
- whatsize
- 0 setgray
- centerstrn
- grestore
- } bind def
-
- /bst {
- gsave
- dup 3 -1 roll
- dup 3 -1 roll
- bs
- exch
- neg
- translate
- blackfont
- dup
- whatsize
- 1 setgray
- centerstrn
- grestore
- } bind def
-
- /centersign {
- sw 2 div neg
- strsize 2 div
- 10 100 div
- sub
- neg
- moveto
- show
- } bind def
-
- /fs {
- gsave
- newpath
- neg
- translate
- 0 0 whiterad 0 360 arc
- 1 setgray
- fill
- fieldfont
- dup
- whatsize
- 0 setgray
- centersign
- grestore
- } bind def
-
- /ps {
- gsave
- /ycoor exch def
- /xcoor exch def
- /color exch def
- color 0 eq {
- xcoor ycoor ws
- } {
- xcoor ycoor bs
- } ifelse
- newpath
- xcoor ycoor neg translate
- .06 setlinewidth
- color setgray
- -.2 0 moveto
- .2 0 lineto
- 0 -.2 moveto
- 0 .2 lineto
- stroke
- grestore
- } bind def
-
- /ms {
- gsave
- /ycoor exch def
- /xcoor exch def
- /color exch def
- color 0 eq {
- xcoor ycoor ws
- } {
- xcoor ycoor bs
- } ifelse
- newpath
- xcoor ycoor neg translate
- .06 setlinewidth
- color setgray
- -.2 0 moveto
- .2 0 lineto
- stroke
- grestore
- } bind def
-
- /ts {
- gsave
- /ycoor exch def
- /xcoor exch def
- /color exch def
- color 0 eq {
- xcoor ycoor ws
- } {
- xcoor ycoor bs
- } ifelse
- newpath
- xcoor ycoor neg translate
- .04 setlinewidth
- color setgray
- -.2353 -.175 moveto
- .2353 -.175 lineto
- 0 .325 moveto
- -.2353 -.175 lineto
- % 0 .325 moveto
- % .2353 -.175 lineto
- closepath
- stroke
- grestore
- } bind def
-
- /comment {
- comntfont
- dup stringwidth pop 2 div neg
- gridmax 2 add neg moveto show
- } bind def
-
- /unresolved {
- gsave
- comntfont
- dup stringwidth pop /width exch def
- 0 gridmax 3 add neg translate
- width gridmax 2 mul gt {
- gridmax 2 mul width div dup scale
- } if
- width 2 div neg 0 moveto show
- grestore
- } bind def
-
- /blackfont {
- /Helvetica-Bold findfont strsize scalefont setfont
- } bind def
- /whitefont {
- /Helvetica findfont strsize scalefont setfont
- } bind def
- /fieldfont {
- /Helvetica findfont strsize scalefont setfont
- } bind def
- /comntfont {
- /Times-Italic findfont strsize scalefont setfont
- } bind def
- %%EndProlog
-
- 19 6.80 boardinit
- SHAR_EOF
- fi
- if test -f 'input.l'
- then
- echo shar: "will not over-write existing file 'input.l'"
- else
- cat << \SHAR_EOF > 'input.l'
-
- %{
- #include "y.tab.h"
- #define STACKLIM 100
-
- extern FILE *infp, *outfp;
- extern char *strsave();
-
- static char istack[ STACKLIM ];
- static int isp = 0;
-
- %}
-
-
- %start IN_BOARD
-
-
- %%
-
- <INITIAL>" +""-"*"+" {BEGIN IN_BOARD;
- yylval.ival = strlen(yytext);
- return(PLUS_DASH_PLUS);
- }
- <INITIAL>"--- Branching to new variation." /* skip */;
- <INITIAL>"--- Backing up" /* skip */;
- <INITIAL>"a b c "([d-t][\n ])* {yylval.sval[0] = '\n';
- return(CHAR);}
- <INITIAL>. {yylval.sval[0] = yytext[0];
- return(CHAR);}
- <IN_BOARD>"..." return(DOTS);
- <IN_BOARD>"." return(DOT);
- <IN_BOARD>"O" return(WHITE);
- <IN_BOARD>"@" return(BLACK);
- <IN_BOARD>"+" return(HANDICAP_PT);
- <IN_BOARD>[A-Za-z] {yylval.sval[0] = yytext[0];
- return(MOVE);}
- <IN_BOARD>[\n\t ] ;
- <IN_BOARD>"|" return(BAR);
- <IN_BOARD>[0-9]+ {
- sscanf(yytext, "%d", &yylval.ival);
- return(NUMBER);
- }
- <IN_BOARD>" +""-"*"+" {BEGIN INITIAL; return(PLUS_DASH_PLUS);}
- <IN_BOARD>. /* skip */ ;
-
-
- SHAR_EOF
- fi
- if test -f 'main.c'
- then
- echo shar: "will not over-write existing file 'main.c'"
- else
- cat << \SHAR_EOF > 'main.c'
- #include <stdio.h>
-
- FILE *infp, *outfp;
- char *strsave();
- extern int yydebug;
-
- main()
- {
- infp = stdin;
- yydebug = 0;
- yyparse();
- }
- SHAR_EOF
- fi
- if test -f 'printps'
- then
- echo shar: "will not over-write existing file 'printps'"
- else
- cat << \SHAR_EOF > 'printps'
- goParse < $1 > x.ps
- cat gopro.ps x.ps > out.ps
- lpr out.ps
- rm out.ps
- SHAR_EOF
- chmod +x 'printps'
- fi
- if test -f 'sample.input'
- then
- echo shar: "will not over-write existing file 'sample.input'"
- else
- cat << \SHAR_EOF > 'sample.input'
- Ok. I've tried it under 4.3 BSD and Dynix 3.0.17.9.
-
- BSD doesn't have any version numbers on Yacc or Lex.
-
- Dynix says yacc is 1.5, lex, 1.4
-
- Here's my test file:
-
-
-
- A B C D E F G H J K L M N O P Q R S T
- +-------------------------------------+
- 19|. . . O . . . . . . . . . . . . . . .|19
- 18|. O . O . . . . . . . . . . . . . . .|18
- 17|. . C O . . . . @ . . . . . . . . . .|17
- 16|O O B O @ . . @ O @ . . . . . . . . .|16
- 15|O . A . . . . . @ . . O . . . . . . .|15
- 14|O O O . . . . . . . . . . . . . . . .|14
- 13|. . . . @ . . . . . . . . . . . . . .|13
- 12|. . . . . . . . O . . O . . . . . . .|12
- 11|. . . . @ 1 @ . . . . . . . . . . . .|11
- 10|. . . + . . . . . + . . . . . + . . .|10
- 9|. . . . . . . 2 . 3 . . . . . . . . .| 9
- 8|. . . . . . . . . . . . . . . . . . .| 8
- 7|. . . . . . . . . . . . . . . . . . .| 7
- 6|. . . . . . . . . . . . . . . . . . .| 6
- 5|. . . . . . . . . . . . . . . . . . .| 5
- 4|. . . + . . . . . + . . . . . + . . .| 4
- 3|. . . . . . . . . . . . . . . . . . .| 3
- 2|. . . . . . . . . . . . . . . . . . .| 2
- 1|. . . . . . . . . . . . . . . . . . .| 1
- +-------------------------------------+ Commands:q><.,ebcx][gnpui
- A B C D E F G H J K L M N O P Q R S T @: 0 O: 0
- White #22 at 'M15'
-
-
-
-
-
-
- A B C D E F G H J K L M N O P Q R S T
- +-------------------------------------+
- 19|. . . . . . . . . . . . . . . . . . .|19
- 18|. . . . . . . . . . . . . . . . . . .|18
- 17|. . . . . . . . . . . . . . . . . . .|17
- 16|. . . @ @ @ @ @ @ @ @ @ @ @ @ @ . . .|16
- 15|. . . O O O O O O O O O . . . . . . .|15
- 14|. . . . . . . . . . . . . . . . . . .|14
- 13|. . . . . . . . . . . . . . . . . . .|13
- 12|. . . . . . . . . . . . . . . . . . .|12
- 11|. . . . . . . . . . . . . . . . . . .|11
- 10|. . . + . . . . . + . . . . . + . . .|10
- 9|. . . . . . . . . . . . . . . . . . .| 9
- 8|. . . . . . . . . . . . . . . . . . .| 8
- 7|. . . . . . . . . . . . . . . . . . .| 7
- 6|. . . . . . . . . . . . . . . . . . .| 6
- 5|. . . . . . . . . . . . . . . . . . .| 5
- 4|. . . + . . . . . + . . . . . + . . .| 4
- 3|. . . . . . . . . . . . . . . . . . .| 3
- 2|. . . . . . . . . . . . . . . . . . .| 2
- 1|. . . . . . . . . . . . . . . . . . .| 1
- +-------------------------------------+ Commands:q><.,ebcx][gnpui
- A B C D E F G H J K L M N O P Q R S T @: 0 O: 0
- White #22 at 'M15'
-
-
-
-
-
-
- SHAR_EOF
- fi
- exit 0
- # End of shell archive
-